﻿using KAKA.Domain;
using KAKA.Repository;
using Morus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KAKA.Controllers
{
    public class FriendController : BaseController
    {
        public FriendController()
            : base()
        {
            MemberRepository = IoC.Resolve<IMemberRepository>();
        }

        public IMemberRepository MemberRepository { get; private set; }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult MakeFriend(string friend)
        {
            if (ModelState.IsValid)
            {
                using (var uow = UnitOfWork.Begin())
                {
                    var self = MemberRepository.Get(CurrentUser.Id);
                    var him = MemberRepository.Get(friend.ToGuid());

                    self.MakeFriend(him);

                    uow.Commit();
                }
            }

            return View();
        }

        public ActionResult Blacklist(string enmity)
        {
            if (ModelState.IsValid)
            {
                using (var uow = UnitOfWork.Begin())
                {
                    var self = MemberRepository.Get(CurrentUser.Id);
                    var him = MemberRepository.Get(enmity.ToGuid());

                    self.Blacklist(him);

                    uow.Commit();
                }
            }

            return View();
        }

    }
}
